﻿using System.Linq;
using Microsoft.Office.Interop.Excel;

namespace ExcelAutomator.Validation
{
	public static class ValidationEngineExtensions
	{
		public static ExcelValidator Excel(this ValidationEngine engine, Workbook workbook)
		{
			var excelValidator = new ExcelValidator(workbook);
			engine.Add(excelValidator);
			return excelValidator;
		}

		public static ExcelValidator WorksheetPreFixIsDefined(this ExcelValidator validator, string address)
		{
			if (string.IsNullOrEmpty(address))
			{
				return validator;
			}

			if (!address.Contains('!'))
			{
				validator.SetFailure(
					string.Format("Worksheet definition is missing for value '{0}'. Expected syntax: 'worksheetName!address'", address), "WorksheetPreFixIsDefined");
			}
			return validator;
		}
	}
}
